<template>
	<view :style="theme">
		<view class="box">
			<view class="box_bg"
				:style="{paddingTop:navigationBarHeight+'rpx',height:navHeight+'rpx',background: 'linear-gradient(180deg,' + 'var(--color2)' + ' 0%, #F7F7F7 100%)'}">
				<!-- 信息 -->
				<view class="box_bg_info" @click="jumpDL">
					<view class="box_bg_info_img">
						<image :src="userInfo.showAvatar ? userInfo.showAvatar : imgHost+'/user.png'"></image>
						</image>
					</view>
					<view class="box_bg_info_xx">
						<view class="box_bg_info_xx_box">
							<text>{{userInfo.nickName ? userInfo.nickName : '默认名称'}}</text>
							<view class="box_bg_info_xx_box_hy" v-if="userInfo.cardName">{{userInfo.cardName}}
							</view>
						</view>
						<text class="phone">{{userInfo.phone}}</text>
						<view v-if="!userInfo" class="btns">点击登录</view>
					</view>
				</view>
				<!-- 订单 -->
				<view class="box_bg_content">
					<view class="box_bt flex flex_between" @click="jump2('/pages/order/list')">
						我的订单
						<text>全部订单 ></text>
					</view>
					<view class="box_bg_content_box">
						<view v-for="(item, index) in orderType" :key="index" class="box_bg_content_item"
							@click="jump2('/pages/order/list?type=', index + 1)">
							<view v-if="item.num" class="box_bg_content_item_num">{{item.num}}</view>
							<image :src="imgHost + item.img"></image>
							<text>{{item.name}}</text>
						</view>
					</view>
				</view>
			</view>
			<view v-if="homeObj['M_SHARE']&&pdShowShareEnter==1" class="share" @click="jump2('/subPackages/share/index')">
				<image :src="homeObj['M_SHARE'].venueContents[0].icon" mode="widthFix"></image>
			</view>
			<!-- 功能菜单 -->
			<view v-if="homeObj['M_MYFUNCTION']" class="woGn" :class="homeObj['M_SHARE']&&pdShowShareEnter==1?'':'on'">
				<view v-if="homeObj['M_MYFUNCTION'].name" class="box_bt">{{homeObj['M_MYFUNCTION'].name}}</view>
				<view class="box_list flex-c">
					<block v-for="(s, m) in homeObj['M_MYFUNCTION'].venueContents" :key="m">
						<view class="li" @click="jumps(s.url)">
							<image :src="s.icon"></image>
							<view>{{s.title}}</view>
						</view>
					</block>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				momConfig: {}, //精彩瞬间配置
				noClick: true,
				navHeight: '',
				navigationBarHeight: '',
				// meta: [],
				orderType: [{
					name: '待付款',
					img: '/mine_ic_daifukuan.png',
					num: 0
				}, {
					name: '已支付',
					img: '/mine_ic_daifahuo.png',
					num: 0
				}, {
					name: '已取消',
					img: '/mine_ic_daishouhuo.png',
					num: 0
				}, {
					name: '退款成功',
					img: '/mine_ic_daipingjia.png',
					num: 0
				}],
				homeObj: {},
				homeList: [],
				pdShowShareEnter: '0'
			}
		},
		created() {
			const SystemInfomations = this.$app.systemInfo()
			/* 通用平台 */
			let navHeight = 100
			let navigationBarHeight = 100
			/* 微信小程序平台 */
			// #ifdef MP-WEIXIN
			navHeight = Number(SystemInfomations.navHeight + SystemInfomations.statusBarHeight) //头部导航栏总高度
			navigationBarHeight = Number(SystemInfomations.navHeight + SystemInfomations.statusBarHeight) //头部导航栏高
			// #endif
			// #ifdef MP-TOUTIAO
			navHeight = 60
			navigationBarHeight = 60
			// #endif 
			this.navHeight = navHeight + 310
			this.navigationBarHeight = navigationBarHeight
		},
		beforeDestroy() {
			uni.$off('onReachBottom');
			uni.$off('onPageScroll');
		},
		methods: {
			jump(url, params, a) {
				this.$app.jump(url, params, a);
			},
		
			jump2(url, params, a) {
				this.$app.jump2(url, params, a);
			},
			showTab() {
				this.getMemberInformation()
				this.getAppHomeRenovationInfo()
			},
			getAuthority() {
				this.$app.ajax({
					data: {
						param: {}
					},
					api: this.$api.showShareEnter()
				}).then((res) => {
					if (res.errorCode === '000000') {
						this.pdShowShareEnter = res.record.show
					}
				}).catch(() => {})

			},
			jumpDL() {
				if (!this.userInfo) {
					this.jump('/pages/home/login')
				} else {
					this.jump2('/pages/home/personal')
				}
			},
			getAppHomeRenovationInfo() {
				this.$app.ajax({
					data: {
						param: {
							code: 'T_MINE'
						}
					},
					api: this.$api.getAppHomeRenovationInfo()
				}).then((res) => {
					if (res.errorCode === '000000') {
						let arr = res.recordList
						let obj = {}
						arr.forEach(s => {
							obj[s.code] = s
							if (s.paramList && s.paramList.length > 0) {
								s.paramShow = s.paramList.map(s => s.key)
							} else {
								s.paramShow = []
							}
						})
						this.homeList = arr
						this.homeObj = obj
					}
				})
			},
			jumps(url) {
				if (url === 'saoma') {
					this.foodBtn()
				} else if(url === '/subPackages/motion/index') {
						this.$app.ajax({
							data: {
								param: {}
							},
							api: this.$api.momOpenStatus()
						}).then(res => {
							if(res.errorCode === '000000'){
								const momConfig = res.record || {}
								if(momConfig.status === '0'){
									this.jump2('/subPackages/motion/index')
								}else{
									this.jump2('/subPackages/motion/indexMiddle')
								}
							}
						})
						
				}  else {
					this.jump2(url)
				}
			},
			foodBtn() {
				if (!this.userInfo) {
					this.$app.showToast('未登录，请先登录！')
					setTimeout(() => {
						this.jump('/pages/home/login')
					}, 1000);
					return false
				}
				let that = this
				uni.scanCode({
					success(res) {
						let path = res.path
						if (res.path) {
							that.jump('/' + res.path)
						} else if (res.result) {
							that.handleQRCode(res.result)
						}
					}
				})
			},
			handleQRCode(code) {
				this.$app.ajax({
					data: {
						param: { code }
					},
					api: this.$api.handleQRCode()
				}).then((res) => {
					if (res.errorCode === '000000') {
						this.$app.showToast('用户授权成功')
					}
				}).catch(() => {})
			},
			getMemberInformation() {
				this.$app.ajax({
					data: {
						param: {}
					},
					api: this.$api.memberInformation()
				}).then((res) => {
					if (res.errorCode === '000000') {
						this.$store.commit('saveUserInfo', res.record);
						this.getAuthority()
						this.getList()
					}
				}).catch(() => {})
			},
			getList() {
				this.$app.ajax({
					data: {
						pagination: {
							page: 1,
							rows: 1
						},
						param: {
							orderStatus: '0'
						}
					},
					api: this.$api.myOrderList()
				}).then((res) => {
					if (res.errorCode === '000000') {
						this.orderType[0].num = res.totalCount
						
					}
				}).catch(() => {})
			},
		}
	}
</script>
<style lang="scss" scoped>
	.box_bg {
		position: relative;
		height: 500rpx;
		padding-top: 80rpx;
		box-sizing: border-box;

		&.wu {
			border-radius: 0;
		}
	}

	.box_bg_content {
		padding: 30rpx 0;
		box-sizing: border-box;
		width: calc(100% - 60rpx);
		position: absolute;
		bottom: -90rpx;
		left: 30rpx;
		right: 0;
		background: #ffffff;
		box-shadow: 0px 2px 16px 0px rgba(0, 0, 0, 0.08);
		border-radius: 16rpx;
		display: flex;
		flex-direction: column;

		.box_bg_content_box {
			display: flex;

			.box_bg_content_item {
				flex: 1;
				display: flex;
				align-items: center;
				flex-direction: column;
				position: relative;

				image {
					width: 60rpx;
					height: 60rpx;
					margin-bottom: 20rpx;
				}

				text {
					font-size: 24rpx;
					font-weight: 400;
					color: #333333;
				}

				.box_bg_content_item_num {
					position: absolute;
					right: 50%;
					top: -5rpx;
					margin-right: -48rpx;
					width: 30rpx;
					height: 30rpx;
					background: $red;
					font-size: 20rpx;
					font-weight: 400;
					color: #ffffff;
					border-radius: 50%;
					display: flex;
					align-items: center;
					justify-content: center;
				}
			}
		}
	}

	.box_bt {
		font-weight: 600;
		color: #222222;
		font-size: 32rpx;
		margin-bottom: 30rpx;
		padding: 0 30rpx;
		box-sizing: border-box;

		text {
			font-size: 26rpx;
			font-family: PingFangSC-Regular, PingFang SC;
			font-weight: 400;
			color: #999999;
		}
	}

	.box_bg_info {
		position: absolute;
		left: 0;
		color: #ffffff;
		padding: 0 30rpx;
		display: flex;
		box-sizing: border-box;
		align-items: center;

		.box_bg_info_img {
			width: 108rpx;
			height: 108rpx;
			overflow: hidden;
			border-radius: 50%;
			box-sizing: border-box;
			border: 5rpx solid #ffffff;

			image {
				width: 100%;
				height: 100%;
			}

		}

		.box_bg_info_xx {
			margin-left: 30rpx;
			display: flex;
			flex-direction: column;

			.phone {
				font-size: 28rpx;
				margin-top: 10rpx;
				color: #666666;
			}

			.box_bg_info_xx_box {
				display: flex;
				line-height: 42rpx;
				align-items: flex-end;
				margin-bottom: 15rpx;

				text {
					font-size: 40rpx;
					font-weight: 600;
					color: #222222;
				}

				.box_bg_info_xx_box_hy {
					padding: 0 15rpx;
					background: $yellow;
					border-radius: 8rpx;
					display: flex;
					height: 42rpx;
					box-sizing: border-box;
					align-items: center;
					justify-content: center;
					font-size: 22rpx;
					line-height: 42rpx;
					font-weight: 400;
					color: #5A1900;
					margin-left: 30rpx;
				}
			}

			.btns {
				background: rgba(0, 0, 0, 0);
				color: rgba(255, 255, 255, 0.8);
				font-size: 24rpx;
				padding: 0 !important;
				margin: 0 !important;
				text-align: left;

				&::after {
					border: none;
				}
			}
		}
	}


	.woGn {
		background: #FFFFFF;
		border-radius: 8rpx;
		padding-top: 30rpx;
		margin-left: auto;
		margin-right: auto;
		width: 690rpx;
		box-sizing: border-box;

		&.on {
			margin-top: 120rpx;
		}

		.box_list {
			flex-wrap: wrap;

			.li {
				width: 25%;
				margin-bottom: 50rpx;
				display: flex;
				flex-direction: column;
				justify-content: center;
				font-size: 28rpx;
				line-height: 1;
				align-items: center;

				image {
					width: 60rpx;
					height: 60rpx;
					margin-bottom: 10rpx;

					&.da {
						width: 88rpx;
						height: 88rpx;
					}
				}
			}
		}
	}


	.share {
		width: 690rpx;
		margin: 114rpx auto 22rpx;

		image {
			width: 100%;
			height: 138rpx;
		}
	}
</style>